package cn.com.tool;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import android.util.Log;

public class Nettool {
	
	public static String getLocalIP()
	{
		try {
			for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
			en.hasMoreElements(); )
			{
				NetworkInterface ni = en.nextElement();
				for(Enumeration<InetAddress> ipAddr = ni.getInetAddresses();
				ipAddr.hasMoreElements(); )
				{
					InetAddress ia = ipAddr.nextElement();
					if(!ia.isLoopbackAddress())
					{
						Log.i("Parser.getLocalIP", ia.getHostAddress().toString());
						return ia.getHostAddress().toString();
					}
				}
			}
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
